<template>
	<view>
		<button @click="getData">加载</button>
		<button @click="addData">添加数据</button>
		<unicloud-db v-slot:default="{data, loading, error, options}" collection="cloudDemo,uni-id-users"
			orderby="posttime desc"
			field="title,content,posttime,userid.username,userid.avatar_file"
			loadtime="auto"
			ref="udb"
		>
			<view v-if="error">{{error.message}}</view>
			<view v-else-if="loading">
				<uni-load-more status="loading"></uni-load-more>
			</view>
			<view v-else>
				<uni-list>
					<uni-list-item
						v-for="item in data"
						:key="item._id"
						:title="item.title"
						:note="item.content"
						:thumb="item.userid[0].avatar_file.url"
						thumb-size="lg"
						:rightText="item.userid[0].username"
						clickable
						@click="onRemove(item._id)"
					></uni-list-item>
				</uni-list>
			</view>
		</unicloud-db>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		onReady() {
		},
		methods: {
			getData() {
				this.$refs.udb.loadData()
			},
			onRemove(id) {
				this.$refs.udb.remove(id)
			},
			addData() {
				let obj = {
					title: '标题',
					content: '内容内容内容内容内容内容内容内容'
				}
				this.$refs.udb.add(obj, {
					toastTitle: '新增成功',
					success: res => {
						this.$refs.udb.loadData()
					}
				})
			}
		}
	}
</script>

<style>

</style>
